package com.cssw.fyzb.busi.api.user;

import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.exception.BizException;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 挂件列表
 *
 * @author YangYiQun
 */
@Function(description = "更新福音号", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = true),
        @Parameter(name = "fyNo", type = Type.Integer, description = "福音号", required = true),
})
@Component
public class UpdateFyNo implements Action {

    @Autowired
    private UserService userService;

    private static final Logger logger = LoggerFactory.getLogger(ListFans.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Long fyNo = request.getLong("fyNo");
        try {
            userService.updateFyNo(userId, fyNo);

            return Response.success();
        } catch (Exception e) {
            if (e instanceof BizException) {
                BizException se = (BizException) e;
                return Response.fail(se.getErrMsg(), se.getErrCode());
            }
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
